package com.ruoyi.boat.controller;

import com.ruoyi.boat.aop.AvoidDuplicate;
import com.ruoyi.boat.domain.MeteorData;
import com.ruoyi.boat.service.IMeteorDataService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 气象数据Controller
 *
 * @author ruoyi
 * @date 2023-08-01
 */
@Controller
@RequestMapping("/boat/meteorData")
public class MeteorDataController extends BaseController {
    private String prefix = "boat/meteorData";

    @Autowired
    private IMeteorDataService meteorDataService;

    @RequiresPermissions("boat:meteorData:view")
    @GetMapping()
    public String meteorData() {
        return prefix + "/meteorData";
    }

    /**
     * 查询气象数据列表
     */
    @RequiresPermissions("boat:meteorData:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MeteorData meteorData) {
        startPage();
        List<MeteorData> list = meteorDataService.selectMeteorDataList(meteorData);
        return getDataTable(list);
    }

    /**
     * 导出气象数据列表
     */
    @RequiresPermissions("boat:meteorData:export")
    @Log(title = "气象数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AvoidDuplicate
    @ResponseBody
    public AjaxResult export(MeteorData meteorData) {
        List<MeteorData> list = meteorDataService.selectMeteorDataList(meteorData);
        ExcelUtil<MeteorData> util = new ExcelUtil<MeteorData>(MeteorData.class);
        return util.exportExcel(list, "气象站数据");
    }

    /**
     * 新增气象数据
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存气象数据
     */
    @RequiresPermissions("boat:meteorData:add")
    @Log(title = "气象数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MeteorData meteorData) {
        return toAjax(meteorDataService.insertMeteorData(meteorData));
    }

    /**
     * 修改气象数据
     */
    @RequiresPermissions("boat:meteorData:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        MeteorData meteorData = meteorDataService.selectMeteorDataById(id);
        mmap.put("meteorData", meteorData);
        return prefix + "/edit";
    }

    /**
     * 修改保存气象数据
     */
    @RequiresPermissions("boat:meteorData:edit")
    @Log(title = "气象数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MeteorData meteorData) {
        return toAjax(meteorDataService.updateMeteorData(meteorData));
    }

    /**
     * 删除气象数据
     */
    @RequiresPermissions("boat:meteorData:remove")
    @Log(title = "气象数据", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(meteorDataService.deleteMeteorDataByIds(ids));
    }
}
